package dp;

import java.util.Arrays;

/**
 * @author : Rookie
 * @description : 最长上升子序列
 * @date : 2023/6/28
 */
public class LongestAscSubsequence {

    public static void main(String[] args) {
        int[] arr = {10, 9, 2, 5, 3, 7, 18, 22};
        System.out.println(getLongestAscSubsequenceLength(arr));
    }

    private static int getLongestAscSubsequenceLength(int []nums) {
        // dp数组代表以nums[i]结尾的最长上升子序列长度
        int[] dp = new int[nums.length];
        int maxLength = 0;
        // 初始化
        Arrays.fill(dp,1);
        for (int i = 0; i < nums.length; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j]) {
                    System.out.println("dp["+i+"]"+"当前值为" + dp[i]+",最终值为"+ dp[i]);
                    dp[i] = Math.max(dp[j] + 1, dp[i]);
                    maxLength = Math.max(maxLength,dp[i]);
                }
            }
        }
        return maxLength;
    }
}
